package com.hr.controller.user;

import com.hr.domain.dto.AiHouseDTO;
import com.hr.domain.query.UserHousePageParams;
import com.hr.domain.query.UserHousePageResult;
import com.hr.domain.vo.UserHouseDetails;
import com.hr.service.HouseService;
import com.hr.service.UserHouseService;
import com.hr.utils.Result;
import com.hr.utils.UserContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/house")
@Tag(name = "用户房源管理")
@AllArgsConstructor
public class UserHouseController {

    private final UserHouseService userHouseService;

    /**
     * 获取用户视角的房源详情
     * @param id 房源ID
     * @return houseDetails
     */
    @GetMapping("/{id}")
    @Operation(summary = "获取用户视角的房源详情")
    public Result getUserHouseDetails(@PathVariable("id") Long id) {
        log.info("获取用户房源详情，houseId: {}", id);
        // 从上下文获取当前登录用户ID
        Long userId = UserContext.getUserId();
        UserHouseDetails details = userHouseService.getUserHouseDetails(id, userId);
        return Result.success(details);
    }

    /**
     * 获取热门房源列表
     * @return houseList
     */
    @GetMapping("/hot")
    @Operation(summary = "获取热门房源列表")
    public Result getHotHouses() {
        log.info("获取热门房源列表");
        // 获取前6条热门房源
        List<UserHouseDetails> hotHouses = userHouseService.getHotHouses(6);
        return Result.success(hotHouses);
    }

    /**
     * 分页获取用户视角的房源列表
     * @return houseList
     */
    @GetMapping("/list")
    @Operation(summary = "分页获取用户视角的房源列表")
    public Result getUserHouseList(UserHousePageParams userHousePageParams) {
        log.info("分页获取用户视角的房源列表");
        // 获取用户视角的房源列表
        UserHousePageResult houseList = userHouseService.getUserHouseList(userHousePageParams);
        return Result.success(houseList);
    }




}
